package com.captjack.common.util;

import java.util.regex.Pattern;

/**
 * <p>
 * ----------------------------------------------------------------------------- <br>
 * project name ：micro-service <br>
 * function：function。。。。。 <br>
 * description：常用正则校验工具类 <br>
 * ----------------------------------------------------------------------------- <br>
 * change history <br>
 * <table width="432" border="1">
 * <tr>
 * <td>version</td>
 * <td>time</td>
 * <td>author</td>
 * <td>change</td>
 * </tr>
 * <tr>
 * <td>1.0.0</td>
 * <td>2018/9/20 14:18</td>
 * <td>Jack Sparrow</td>
 * <td>create</td>
 * </tr>
 * </table>
 * <br>
 *
 * @author Jack Sparrow
 * @version 1.0.0
 * @date 2018/9/20 14:18
 * package com.captjack.common.util
 */
public enum PatternValidateTool {

    /**
     * email校验
     */
    EMAIL(""),

    /**
     * 移动电话号码
     */
    MOBILE_PHONE_NUMBER("");

    /**
     * pattern
     */
    private final Pattern pattern;

    PatternValidateTool(String regex) {
        this.pattern = Pattern.compile(regex);
    }

    /**
     * @param regex   正则式
     * @param pattern 匹配模式
     */
    PatternValidateTool(String regex, int pattern) {
        this.pattern = Pattern.compile(regex, pattern);
    }

    public Pattern getPattern() {
        return this.pattern;
    }

    /**
     * 是否通过匹配
     *
     * @param testString 测试字符串
     * @return boolean
     */
    public boolean match(String testString) {
        return this.pattern.matcher(testString).matches();
    }

}
